/**
 * <p>
 * 版权所有：中企动力
 * </p>
 * <p>
 * 未经本公司许可，不得以任何方式复制或使用本程序任何部分
 * </p>
 */
package com.ce.pms.report.service;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.ce.pms.report.queryvo.AccountClientChangeListQueryVo;
import com.ce.pms.report.vo.AccountClientChangeListVo;
import com.ce.pms.report.vo.BaseReportVo;
import com.ce.report.entity.CEReportDataSet;
import com.ce.report.exception.CEReportException;
import com.ce.report.service.ICEReportDataSetService;
import com.ce.report.vo.ReportsQueryBaseVo;
import com.ce.util.DateUtil;

/**
 * 帐号客户变更通知单
 * 
 * @author <a href="mailto:i0o@live.cn">黄腾飞</a>
 * @Created 2008-11-14
 */

public class AccountClientChangeListService extends BaseReportService implements
		ICEReportDataSetService {

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.ce.pms.report.service.BaseReportService#converToReportVoList(java
	 * .util.List)
	 */
	@Override
	protected List<BaseReportVo> converToReportVoList(List<Object[]> dataList) {
		List<BaseReportVo> voList = new ArrayList<BaseReportVo>();

		for (Object[] objTmp : dataList) {
			AccountClientChangeListVo voTmp = new AccountClientChangeListVo();

			voTmp.setHouseNumber((String) objTmp[0]);
			voTmp.setUserName((String) objTmp[1]);
			voTmp.setAccounts((String) objTmp[2]);
			voTmp.setChangeDate((Date) objTmp[3]);
			voTmp.setIntrinsicUserName((String) objTmp[4]);
			voTmp.setConsignAccounts((String) objTmp[5]);

			voList.add(voTmp);
		}
		return voList;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.ce.report.service.ICEReportDataSetService#getReportDataSet(com.ce
	 * .report.vo.ReportsQueryBaseVo)
	 */
	public CEReportDataSet getReportDataSet(ReportsQueryBaseVo queryVO)
			throws CEReportException {
		AccountClientChangeListQueryVo accl = (AccountClientChangeListQueryVo) queryVO;

		String precincId = accl.getPrecinct();

		String buildingId = accl.getBuildingId();

		String beginDate = DateUtil.convertDateToStr(accl.getBeginDate(),
				"yyyyMMdd");

		String endDate = DateUtil.convertDateToStr(accl.getEndDate(),
				"yyyyMMdd");

		Object[] obj = { precincId, buildingId, beginDate, endDate };

		List<Object[]> list = reportDao.getDataList("AccountClientChangeList",
				obj);

		// 报表用数据集
		List<BaseReportVo> reportDate = converToReportVoList(list);

		// 返回报表数据
		return new CEReportDataSet(reportDate, getHeadInfo(accl));
	}

	/**
	 * 报表头信息
	 * 
	 * @param queryVO
	 * @return
	 * @author <a href="mailto:i0o@live.cn">黄腾飞</a>
	 * @created 2008-11-28
	 */
	private Map<String, Object> getHeadInfo(
			AccountClientChangeListQueryVo queryVO) {
		String beginDate = DateUtil.convertDateToStr(queryVO.getBeginDate(),
				"yyyyMMdd");
		String endDate = DateUtil.convertDateToStr(queryVO.getEndDate(),
				"yyyyMMdd");

		Map<String, Object> headerMap = new HashMap<String, Object>();
		headerMap.put("reportHeadStr", "统计时间:" + beginDate + "-" + endDate);
		headerMap.put("printDate", new Date());

		return headerMap;
	}

}
